package com.cheung.leetcode.dp;

import org.junit.jupiter.api.Test;

/**
 * @BelongsProject : java-leetcode
 * @BelongsPackage : com.cheung.leetcode.dp
 * @Author :  cheungming
 * @CreateTime : 2024-06-15 09:33:14
 * @Description : 组合总和4
 * @Version : 1.0
 */
public class Code377Test {

    public int combinationSum4(int[] nums, int target) {
        int[] dp = new int[target + 1];
        dp[0] = 1;
        for (int i = 0; i <= target; i++) {
            for (int num : nums) {
                if (i >= num) {
                    dp[i] += dp[i - num];
                }
            }
        }
        return dp[target];
    }


    @Test
    public void test1() {
        assert combinationSum4(new int[]{1, 2, 3}, 4) == 7;
    }

    @Test
    public void test2() {
        assert combinationSum4(new int[]{9}, 3) == 0;
    }
}
